package com.example.lbstest.controller;

import com.example.lbstest.impl.CardMapperServiceImpl;
import com.example.lbstest.impl.ScoreMapperServiceImpl;
import com.example.lbstest.pojo.Card;
import com.example.lbstest.pojo.Score;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

@Controller
@RequestMapping("/score")
public class ScoreController {
    @Autowired
    ScoreMapperServiceImpl scoreMapperService;

    @RequestMapping("/insertOneScore")
    @ResponseBody
    public String insertOneScore(@RequestParam("class_number")String class_number,
                                 @RequestParam("student_number")String student_number,
                                 @RequestParam("test_name")String test_name,
                                 @RequestParam("score")String score,
                                 @RequestParam("score_format")String score_format,
                                 @RequestParam("class_name")String class_name){
        Score scoreBean = new Score();
        scoreBean.setClass_name(class_name);
        scoreBean.setClass_number(class_number);
        scoreBean.setScore_format(score_format);
        scoreBean.setScore(Integer.valueOf(score));
        scoreBean.setStudent_number(student_number);
        scoreBean.setTest_name(test_name);
        int rr = scoreMapperService.insertOneScore(scoreBean);
        if(rr == 1){
            System.out.println("-----成绩上传成功-------");
            return "success";
        }else{
            System.out.println("-----成绩上传失败-------");
        }
        return "fail";
    }

    @RequestMapping("/selectOnePersonScore")
    @ResponseBody
    public Score selectOnePerSonScore(@RequestParam("student_number")String student_number,
                                      @RequestParam("class_number")String class_number,
                                      @RequestParam("test_name")String test_name){
        Score score = scoreMapperService.selectOnePersonScore(student_number, class_number, test_name);
        if(score != null){
            System.out.println("-----成绩查询成功-----");
        }else{
            System.out.println("------成绩查询失败----");
        }
        return score;
    }

    @RequestMapping("/selectScoreList")
    @ResponseBody
    public List<Score> selectScoreList(@RequestParam("class_number") String class_number,
                                       @RequestParam("test_name") String test_name){
        List<Score> scoreList = scoreMapperService.selectScoreList(class_number, test_name);
        if(scoreList != null){
            System.out.println("-----成绩列表查询成功-----");
        }else{
            System.out.println("-----成绩列表查询失败-----");
        }
        return scoreList;
    }

    @RequestMapping("/selectScoreMax")
    @ResponseBody
    public String selectScoreMax(@RequestParam("class_number") String class_number,
                                 @RequestParam("test_name") String test_name){
        int max = scoreMapperService.selectScoreMax(class_number, test_name);
        return String.valueOf(max);
    }

    @RequestMapping("/selectTestName")
    @ResponseBody
    public List<String> selectTestName(@RequestParam("class_number")String class_number){
        List<String> listTestName = scoreMapperService.selectTestName(class_number);
        if(listTestName != null){
            System.out.println("-------查询成功TestName------");
        }else{
            System.out.println("-------查询失败TestName------");
        }
        return listTestName;
    }


}
